package com.atguigu.gmall.cart.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.atguigu.gmall.cart.mapper.CartInfoMapper;
import com.atguigu.gmall.cart.service.CartInfoAsyncService;
import com.atguigu.gmall.model.cart.CartInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

@Service
public class CartInfoAsyncServiceImpl implements CartInfoAsyncService {

    @Autowired
    private CartInfoMapper cartInfoMapper;
    //更新DB 购物车 异步
    @Override
    @Async
    public void updateAsyncById(CartInfo cartInfo) {

        System.out.println("updateAsyncById:" + JSONObject.toJSONString(cartInfo));
        System.out.println("update线程名为：" + Thread.currentThread().getName());
        cartInfoMapper.updateById(cartInfo);
    }

    @Override
    @Async
    public void insertAsync(CartInfo cartInfo) {
        System.out.println("insert线程名为：" + Thread.currentThread().getName());
        cartInfoMapper.insert(cartInfo);
    }
}
